# 视频接收端
import cv2
import zmq
import base64
import numpy as np
 
# 初始化 ZeroMQ
class img_pub():
    def __init__(self,ip,COM):
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.PUB)
        self.socket.bind("tcp://"+ip+f":{COM}")
    
    def send_img(self,img):
        # 将帧转换为 JPEG 格式
        _, buffer = cv2.imencode('.jpg', img)
        encoded_image = base64.b64encode(buffer)
        # 发布帧数据
        self.socket.send(encoded_image)